/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import com.openbrew.openbrewrf.views.BrewView;
import com.openbrew.openbrewrf.views.CustomerView;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "Firkins")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Firkins.findAll", query = "SELECT f FROM Firkins f"),
    @NamedQuery(name = "Firkins.findByFirkID", query = "SELECT f FROM Firkins f WHERE f.firkID = :firkID"),
    @NamedQuery(name = "Firkins.findByFirkDesc", query = "SELECT f FROM Firkins f WHERE f.firkDesc = :firkDesc"),
    @NamedQuery(name = "Firkins.findByFirkSold", query = "SELECT f FROM Firkins f WHERE f.firkSold = :firkSold"),
    @NamedQuery(name = "Firkins.findByFirkVolume", query = "SELECT f FROM Firkins f WHERE f.firkVolume = :firkVolume"),
    @NamedQuery(name = "Firkins.findByFirkDate", query = "SELECT f FROM Firkins f WHERE f.firkDate = :firkDate"),
    @NamedQuery(name = "Firkins.findByFirkCustomerID", query = "SELECT f FROM Firkins f WHERE f.firkCustomerID = :firkCustomerID"),
    @NamedQuery(name = "Firkins.findByFirkSalesDate", query = "SELECT f FROM Firkins f WHERE f.firkSalesDate = :firkSalesDate"),
    @NamedQuery(name = "Firkins.findByFirkCost", query = "SELECT f FROM Firkins f WHERE f.firkCost = :firkCost"),
    @NamedQuery(name = "Firkins.findAllUnsold", query = "SELECT f FROM Firkins f WHERE f.firkSold = 'false'"),
    @NamedQuery(name = "Firkins.findAllSold", query = "SELECT f FROM Firkins f WHERE f.firkSold = 'true'")})
public class Firkins implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "FirkID")
    private Integer firkID;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 250)
    @Column(name = "FirkDesc")
    private String firkDesc;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 0, max = 65535)
    @Column(name = "FirkRecipe")
    private String firkRecipe;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 0, max = 65535)
    @Column(name = "FirkResults")
    private String firkResults;
    @Basic(optional = false)
    @NotNull
    @Column(name = "FirkSold")
    private boolean firkSold;
    @Basic(optional = false)
    @NotNull
    @Column(name = "FirkVolume")
    private float firkVolume;
    //@Basic(optional = false)
    //@NotNull
    @Column(name = "FirkDate")
    @Temporal(TemporalType.DATE)
    private Date firkDate;
    //@Basic(optional = false)
    //@NotNull
    @Column(name = "FirkSalesDate")
    @Temporal(TemporalType.DATE)
    private Date firkSalesDate;
    @Basic(optional = false)
    @NotNull
    @Column(name = "FirkCost")
    private float firkCost;
    @JoinColumn(name = "FirkCustomerID", referencedColumnName = "CId", nullable=true)
    @ManyToOne(optional = true)
    private CustomerView firkCustomerID;
    @JoinColumn(name = "FirkBatchID", referencedColumnName = "BID")
    @ManyToOne(optional = false)
    private BrewView firkBatchID;

    public Firkins() {
    }

    public Firkins(Integer firkID) {
        this.firkID = firkID;
    }

    public Firkins(Integer firkID, String firkDesc, String firkRecipe, String firkResults, boolean firkSold, float firkVolume, Date firkDate, Date firkSalesDate, float firkCost) {
        this.firkID = firkID;
        this.firkDesc = firkDesc;
        this.firkRecipe = firkRecipe;
        this.firkResults = firkResults;
        this.firkSold = firkSold;
        this.firkVolume = firkVolume;
        this.firkDate = firkDate;
        this.firkSalesDate = firkSalesDate;
        this.firkCost = firkCost;
    }

    public Integer getFirkID() {
        return firkID;
    }

    public void setFirkID(Integer firkID) {
        this.firkID = firkID;
    }

    public String getFirkDesc() {
        return firkDesc;
    }

    public void setFirkDesc(String firkDesc) {
        this.firkDesc = firkDesc;
    }

    public BrewView getFirkBatchID() {
        return firkBatchID;
    }

    public void setFirkBatchID(BrewView firkBatchID) {
        this.firkBatchID = firkBatchID;
    }

    public String getFirkRecipe() {
        return firkRecipe;
    }

    public void setFirkRecipe(String firkRecipe) {
        this.firkRecipe = firkRecipe;
    }

    public String getFirkResults() {
        return firkResults;
    }

    public void setFirkResults(String firkResults) {
        this.firkResults = firkResults;
    }

    public boolean getFirkSold() {
        return firkSold;
    }

    public void setFirkSold(boolean firkSold) {
        this.firkSold = firkSold;
    }

    public float getFirkVolume() {
        return firkVolume;
    }

    public void setFirkVolume(float firkVolume) {
        this.firkVolume = firkVolume;
    }

    public Date getFirkDate() {
        return firkDate;
    }

    public void setFirkDate(Date firkDate) {
        this.firkDate = firkDate;
    }

    public CustomerView getFirkCustomerID() {
        return firkCustomerID;
    }

    public void setFirkCustomerID(CustomerView firkCustomerID) {
        if(firkCustomerID.getcId()!=null && firkCustomerID.getcId()!=0){
            this.firkCustomerID = firkCustomerID;
        }
    }

    public Date getFirkSalesDate() {
        return firkSalesDate;
    }

    public void setFirkSalesDate(Date firkSalesDate) {
        this.firkSalesDate = firkSalesDate;
    }

    public float getFirkCost() {
        return firkCost;
    }

    public void setFirkCost(float firkCost) {
        this.firkCost = firkCost;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (firkID != null ? firkID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Firkins)) {
            return false;
        }
        Firkins other = (Firkins) object;
        if ((this.firkID == null && other.firkID != null) || (this.firkID != null && !this.firkID.equals(other.firkID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.Firkins[ firkID=" + firkID + " ]";
    }

    public Date getDueDate(final int term) {
        final Calendar cal = Calendar.getInstance();
        cal.setTime(this.firkSalesDate);
        cal.add(Calendar.DATE, term);
        return new Date(cal.getTime().getTime());
    }
    
}
